package cn.csg.iotplatform.module.system.controller.admin.menu;

import cn.csg.iotplatform.framework.common.pojo.CommonResult;
import cn.csg.iotplatform.framework.operatelog.core.annotations.OperateLog;
import cn.csg.iotplatform.module.system.controller.admin.menu.vo.SystemMenuReqVO;
import cn.csg.iotplatform.module.system.dal.dataobject.menu.MenuCollectionDO;
import cn.csg.iotplatform.module.system.service.menu.SystemMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;

import java.util.List;

import static cn.csg.iotplatform.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - 菜单")
@RestController

@RequestMapping("/system/menu")
@Validated
@Slf4j
public class SystemMenuController {

    @Resource
    private SystemMenuService systemMenuService;

    @PostMapping("/menuCollectionOrNot")
    @PermitAll
    @Operation(summary = "菜单收菜与否")
    @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
    public CommonResult<Object> menuCollectionOrNot(@RequestBody SystemMenuReqVO systemMenuReqVO){
        return success(systemMenuService.menuCollectionOrNot(systemMenuReqVO));
    }

    @GetMapping("/selectMenuCollections")
    @PermitAll
    @Operation(summary = "查询收藏菜单")
    @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
    public CommonResult<Object> selectMenuCollections(String userId){

        return success(systemMenuService.selectMenuCollections(userId));
    }

    @PostMapping("/menuHistoryCollections")
    @PermitAll
    @Operation(summary = "新增菜单历史记录")
    @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
    public CommonResult<String> menuHistoryCollections(@RequestBody SystemMenuReqVO systemMenuReqVO){
        return success(systemMenuService.menuHistoryCollections(systemMenuReqVO));
    }

    @GetMapping("/selectMenuHistory")
    @PermitAll
    @Operation(summary = "查询菜单历史记录")
    @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
    public CommonResult<Object> selectMenuHistory(){
        return success(systemMenuService.selectMenuHistory());
    }

}
